
import { EChartFormItem, EMateDataType, IChartFormItem } from "./ChartItemType"

export default class ChartFormItem implements IChartFormItem {
    public label: string = "";
    public value: any = "";
    public placeHolder: string = "";
    public name: string = "";
    public datas?: any = {};
    public type: EChartFormItem = EChartFormItem.Input;
    public shouldRender: boolean = true;
    public computed: any = {};
    public default: any = {};
    public isMultiple: boolean = false;
    public disabled: boolean = false;
    public mateData?: { type: EMateDataType; } | undefined;
    constructor(param: IChartFormItem) {
        this.label = param.label || "";
        this.value = param.value || "";
        this.placeHolder = param.placeHolder || "";
        this.name = param.name || "";
        this.datas = param.datas || "";
        this.computed = param.computed || {};
        this.type = param.type || EChartFormItem.Input;
        this.shouldRender = param.shouldRender === false ? param.shouldRender : true;
        this.disabled = param.disabled === false ? param.disabled : true;
        this.isMultiple = param.isMultiple || false;
        this.mateData = param.mateData;
        this.default = param.default || {};
    }
    get current(): IChartFormItem {
        return {
            label: this.label,
            value: this.value,
            placeHolder: this.placeHolder,
            name: this.name,
            disabled: this.disabled,
            datas: this.datas,
            type: this.type,
            shouldRender: this.shouldRender,
            mateData: this.mateData,
            computed: this.computed,
            default: this.default,
            isMultiple: this.isMultiple
        }
    }
}

export class ChartFormItemContext {
    private item: ChartFormItem;
    constructor(item: IChartFormItem) {
        this.item = new ChartFormItem(item);
    }
    get data() {
        return this.item.datas;
    }
    get currentChartForm() {
        return this.item;
    }
    get name() {
        return this.item.name;
    }
    setItemName(name: string) {
        this.item.name = name;
    }
    setItemDatas(datas: any) {
        this.item.datas = datas;
    }
}